package 力扣._00周赛._427周赛.问题2;

class Solution {
    public int maxRectangleArea(int[][] points) {
        // 暴力解法
        int max = -1;
        int n = points.length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    for (int l = 0; l < n; l++) {
                        // i: 左上， j: 右上， k: 左下， l: 右下
                        if(points[i][1] == points[j][1]
                                && points[k][1] == points[l][1]
                                && points[i][0] == points[k][0]
                                && points[j][0] == points[l][0]){
                            // 该矩形中间或边上没有其他点
                            // 左上
                            int a = points[i][0] , b = points[i][1];
                            // 右下
                            int c = points[l][0] , d = points[l][1];
                            if(a>=c || b>=d){
                                continue;
                            }
                            // 判断是否有点在矩形内
                            boolean flag = false;
                            for (int m = 0; m < n; m++) {
                                if(m!=i && m!=j && m!=k && m!=l) {
                                    if (points[m][0] > a && points[m][0] < c
                                            && points[m][1] > b && points[m][1] < d) {
                                        flag = true;
                                        break;
                                    }
                                    // 边上
                                    if ((points[m][0] == a && points[m][1] > b && points[m][1] < d)||
                                            (points[m][0] == c && points[m][1] > b && points[m][1] < d)||
                                            (points[m][1] == b && points[m][0] > a && points[m][0] < c)||
                                            (points[m][1] == d && points[m][0] > a && points[m][0] < c)
                                    ) {
                                        flag = true;
                                        break;
                                    }
                                }
                            }
                            if(flag)
                                continue;




                            int area = Math.abs(points[j][0] - points[i][0]) *
                                    Math.abs((points[k][1] - points[i][1]));
                            max = Math.max(max, area);
                        }

                    }
                }
            }
        }
        return max;

    }
}